//var dataid= [];
Ext.define('NIM.view.Administration.Warehouse', {
    extend: 'Ext.panel.Panel',
    alias: 'widget.Warehouse',
    id: 'warehouse',
    title: 'WareHouse',
    border: false,
    height: 590,
    closable: true,
    layout: {
        type: 'border'
    },
    listeners: {
        afterrender: function () {
            Ext.getStore('Administration.Warehouse').load();
        }
    },
    items: [{
            xtype: 'form',
            id: 'ConfigWareHouse',
            title: 'Configuration',
            region: 'west',
            margin: '5 5 5 5',
            method: 'POST',
            url: './Services/DataMaster/Warehouse/Add',
            collapsed: true,
            collapsible: true,
            width: 350,
            items: [
                {
                    xtype: 'hiddenfield',
                    cls: 'black',
                    id: 'whId',
                    name: 'WH_ID',
                    margin: '5 10 5 25',
                    labelWidth: 100 / 1366 * screen.width,
                    width: 300 / 1366 * screen.width,
                    fieldLabel: 'WH ID',
                    msgTarget: 'title',
                    allowBlank: true,
                    validateBlank: false

                },
                {
                    xtype: 'textfield',
                    cls: 'black',
                    name: 'WH_CODE',
                    //id : 'whcode',
                    // emptyText: 'Input Main Category',
                    margin: '15 10 10 10',
                    labelWidth: 130 / 1366 * screen.width,
                    width: 325 / 1366 * screen.width,
                    fieldLabel: 'WareHouse Code',
                    msgTarget: 'title',
                    allowBlank: true,
                    validateBlank: false,
                    // allowOnlyWhitespace: false
                }, {
                    xtype: 'textfield',
                    cls: 'black',
                    name: 'WH_CATEGORY',
                    //id : 'whcategory',
                    // emptyText: 'Input Sub Category 1',
                    margin: '10 10 10 10',
                    labelWidth: 130 / 1366 * screen.width,
                    width: 325 / 1366 * screen.width,
                    fieldLabel: 'WareHouse Category',
                    msgTarget: 'title',
                    allowBlank: true,
                    // allowOnlyWhitespace: false
                }, {
                    xtype: 'textareafield',
                    grow: true,
                    //id : 'whdesc',
                    name: 'WH_DESC',
                    labelWidth: 130 / 1366 * screen.width,
                    width: 325 / 1366 * screen.width,
                    margin: '10 10 10 10',
                    fieldLabel: 'Description',
                    anchor: '100%',
                }, {
                    xtype: 'textareafield',
                    grow: true,
                    name: 'ADDRESS1',
                    //id : 'whaddress1',
                    labelWidth: 130 / 1366 * screen.width,
                    width: 325 / 1366 * screen.width,
                    margin: '10 10 10 10',
                    fieldLabel: 'Address 1',
                    anchor: '100%',
                }, {
                    xtype: 'textareafield',
                    grow: true,
                    name: 'ADDRESS2',
                    //id : 'whaddress2',
                    labelWidth: 130 / 1366 * screen.width,
                    width: 325 / 1366 * screen.width,
                    margin: '10 10 10 10',
                    fieldLabel: 'Address 2',
                    anchor: '100%',
                }, {
                    xtype: 'textfield',
                    cls: 'black',
                    name: 'CITY',
                    //id : 'city',
                    // emptyText: 'Input Sub Category 3',
                    margin: '10 10 10 10',
                    labelWidth: 130 / 1366 * screen.width,
                    width: 325 / 1366 * screen.width,
                    fieldLabel: 'City',
                    msgTarget: 'title',
                    allowBlank: true,
                    // allowOnlyWhitespace: false
                }, {
                    xtype: 'textfield',
                    cls: 'black',
                    name: 'PHONE',
                    //id : 'whphone',
                    // emptyText: 'Input Sub Category 3',
                    margin: '10 10 10 10',
                    labelWidth: 130 / 1366 * screen.width,
                    width: 325 / 1366 * screen.width,
                    fieldLabel: 'Phone',
                    msgTarget: 'title',
                    allowBlank: true,
                    // allowOnlyWhitespace: false
                }, {
                    xtype: 'textfield',
                    cls: 'black',
                    name: 'FAX',
                    //id : 'whfax',
                    // emptyText: 'Input Sub Category 3',
                    margin: '10 10 10 10',
                    labelWidth: 130 / 1366 * screen.width,
                    width: 325 / 1366 * screen.width,
                    fieldLabel: 'Facsimile',
                    msgTarget: 'title',
                    allowBlank: true,
                    // allowOnlyWhitespace: false
                },
                {
                    xtype: 'fieldcontainer',
                    cls: 'black',
                    name: 'ENABLED',
                    margin: '10 10 10 10',
                    fieldLabel: 'Status',
                    labelWidth: 130 / 1366 * screen.width,
                    width: 325 / 1366 * screen.width,
                    defaultType: 'radiofield',
                    defaults: {
                        flex: 1
                    },
                    layout: 'hbox',
                    items: [{
                            boxLabel: 'Yes',
                            //id : 'active_category1',
                            name: 'active',
                            inputValue: 'y'
                        }, {
                            boxLabel: 'No',
                            //id : 'disactive_category1',
                            name: 'active',
                            inputValue: 'n'
                        }]
                }, {
                    xtype: 'button',
                    id: 'ButtonAddWh',
                    margin: '5 10 10 10',
                    width: 50 / 1366 * screen.width,
                    text: 'Insert',
                    handler: function () {
                        this.up('form').getForm().submit({
                            waitMsg: 'Please Wait ....',
                            success: function (form, action) {
                                afterSubmitInformation(form, action);
                                this.up('form').getForm().reset();
                                RefreshWarehouse();
                            },
                            failure: function (form, action) {
                                afterSubmitInformation(form, action);
                            }
                        })
                        Ext.getCmp('ButtonAddWh').setText('Insert');
                        //InputWarehouse();
                    },
                }, {
                    xtype: 'button',
                    margin: '5 10 10 0',
                    id: 'ButtonClear',
                    width: 50 / 1366 * screen.width,
                    text: 'Clear',
                    handler: function () {
                        emptyfield();
                    }
                }]
        },
        {
            xtype: 'gridpanel',
            region: 'center',
            id: 'table_Warehouse',
            height: 590,
            width: 400,
            titleAlign: 'center',
            margin: '5 5 5 0',
            border: true,
            forceFit: true,
            columnLines: true,
            selType: 'checkboxmodel',
            store: 'Administration.Warehouse',
            title: 'WareHouse List',
            columns: [{
                    dataIndex: 'WH_CODE',
                    width: 70,
                    text: 'WH CODE',
                    align: 'left'
                }, {
                    dataIndex: 'WH_CATEGORY',
                    text: 'WH CATEGORY',
                    align: 'left'
                }, {
                    dataIndex: 'WH_DESC',
                    text: 'WH DESC',
                    align: 'left'
                },
                // { dataIndex: 'ADDRESS1', text: 'ADDRESS1', align: 'left' },
                // { dataIndex: 'ADDRESS2', text: 'ADDRESS2', align: 'left' },
                {
                    dataIndex: 'CITY',
                    text: 'CITY',
                    align: 'left'
                }, {
                    dataIndex: 'PHONE',
                    text: 'PHONE',
                    align: 'left'
                }, {
                    dataIndex: 'FAX',
                    text: 'FAX',
                    align: 'left'
                }, {
                    dataIndex: 'ENABLED',
                    width: 50,
                    text: 'ENABLED',
                    align: 'left'
                }

            ],
            dockedItems: [
                {
                    xtype: 'pagingtoolbar',
                    dock: 'bottom',
                    store: 'Administration.Warehouse',
                    displayInfo: true
                }, {
                    xtype: 'toolbar',
                    dock: 'top',
                    items: [
                        {
                            xtype: 'textfield',
                            fieldLabel: 'KEYWORD',
                            id: 'keywordWarehouse',
                            margin: '0 0 0 10',
                            enableKeyEvents: true,
                            listeners: {
                                keypress: function (form, e) {
                                    if (e.getKey() == 13) {
                                        SearchWarehouse();
                                    }

                                }
                            }
                        }, {
                            xtype: 'button',
                            text: 'SEARCH',
                            margin: '0 30 0 0',
                            handler: function () {
                                SearchWarehouse();
                            }
                        }, {
                            xtype: 'button',
                            text: 'ADD NEW',
                            margin: '0 20 0 0',
                            handler: function () {
                                emptyfield();
                                if (Ext.getCmp('ConfigWareHouse').hidden == true)
                                    Ext.getCmp('ConfigWareHouse').toggleCollapse(true);
                            }

                        },
                        {
                            xtype: 'button',
                            text: 'DELETE',
                            margin: '0 20 0 0',
                            handler: function () {
                                DeleteWarehouse();
                            }
                        }, 
                        {
                            xtype: 'button',
                            text: 'REFRESH',
                            handler: function () {
                                RefreshWarehouse();
                            }
                        }]
                }],
            listeners: {
                afterrender: function () {
                    Ext.getStore('Administration.Warehouse').load();
                },
                itemdblclick: function (grid, record) {
                    if (Ext.getCmp('ConfigWareHouse').hidden == true)
                        Ext.getCmp('ConfigWareHouse').toggleCollapse(true);
                    getValueGridWarehouse(record);
                }

            },
        }]

});